<?php
require_once(dirname(__FILE__)."/../include/common.inc.php");
require_once(DEDEINC.'/memberlogin.class.php');
$cfg_ml = new MemberLogin();

if($cfg_ml->M_ID==0)
{
	echo"<script>history.go(-1);</script>";
	//ShowMsg("请先登录！","-1",0,2000);
	exit;
}

if($type=='fankui')
{
	  if($conte=='') 
	  {
        ShowMsg("反馈内容不能为空！", "-1", 0, 2000);
        exit();
      }
      if($contesfs=='')
      {
        ShowMsg("联系方式不能为空！","-1",0,2000);
        exit();
      }
	  else
	  { 
	  	if($lxlx=='QQ')
		{
			if(!is_numeric($contesfs))
			{
				ShowMsg("QQ号码格式错误！","-1",0,2000);
       		    exit();
			}
		}
		else if($lxlx=='手机')
		{
			if(!preg_match("/^13[0-9]{1}[0-9]{8}$|15[0-9]{1}[0-9]{8}$|18[0-9]{9}$|17[0-9]{1}[0-9]{8}$|14[0-9]{1}[0-9]{8}$/",$contesfs))
			{
				ShowMsg("手机号码格式错误！","-1",0,2000);
				exit();
			} 
		}
		else if($lxlx=='邮箱')
		{
			$regex = '/^[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+)*@(?:[-_a-z0-9][-_a-z0-9]*\.)*(?:[a-z0-9][-a-z0-9]{0,62})\.(?:(?:[a-z]{2}\.)?[a-z]{2,})$/i';
			if(!preg_match($regex, $contesfs))
			{
				ShowMsg("邮箱格式错误！","-1",0,2000);
				exit();
			} 
		}
	  }
	  $row = $dsql->GetOne("SELECT * FROM `#@__member` WHERE mid='1'");
	  $uid = $row['userid'];
	  
	  $row = $dsql->GetOne("SELECT * FROM `#@__member_pms` WHERE fromid='".$cfg_ml->M_ID."' AND hasview='0'");
	  if($row)
	  {
		  ShowMsg('您提交的反馈留言还有未处理的，请等待管理员处理后再提交', '-1');
		  exit(0);
	  }
	  else
	  {
		  $inquery = "INSERT INTO `#@__member_pms`(floginid,fromid,toid,tologinid,folder,subject,sendtime,writetime,hasview,isadmin,message,contesfs,lxlx,type) VALUES ('".$cfg_ml->M_LoginID."','".$cfg_ml->M_ID."','1','$uid','inbox','来自".$cfg_ml->M_UserName."的留言','".time()."','".time()."','0','0','$conte','$contesfs','$lxlx','2'); ";
		  //记录数据
		  if( !$dsql->ExecuteNoneQuery($inquery) ){
			ShowMsg('记录数据失败, 请返回', '-1');
			exit(0);
		  }else{
			ShowMsg("提交成功，等待管理员回复！","-1",0,2000);
			echo"<script>history.go(-1);</script>";
		  }
	  }
}
else if($type=='wliuyan')
{
	  if($title=='') 
	  {
        ShowMsg("消息标题不能为空！", "-1", 0, 2000);
        exit();
      }
      if($wneir=='')
      {
        ShowMsg("消息内容不能为空！","-1",0,2000);
        exit();
      }
	  /*已经提交过一次反馈且管理员未处理的 不能再次提交
	  $row = $dsql->GetOne("SELECT * FROM `#@__member_pms` WHERE mid='".$cfg_ml->M_ID."' AND hasview='0'");
	  if($row)
	  {
		 ShowMsg('您提交的反馈还有未处理的，请勿重复提交', '-1');
		 exit(0);
	  }*/
	  $row = $dsql->GetOne("SELECT * FROM `#@__member` WHERE mid='$wid'");
	  $uid = $row['userid'];
	  $inquery = "INSERT INTO `#@__member_pms`(floginid,fromid,toid,tologinid,folder,subject,sendtime,writetime,hasview,isadmin,message,contesfs,lxlx,type) VALUES ('".$cfg_ml->M_LoginID."','".$cfg_ml->M_ID."','$wid','$uid','inbox','管理员在素材[".$arctitle."]中发的消息','".time()."','".time()."','0','0','$wneir','','','3'); ";
	  //记录数据
	  if( !$dsql->ExecuteNoneQuery($inquery) ){
		ShowMsg('记录数据失败, 请返回', '-1');
		exit(0);
	  }else{
		//header("Location:$backurl"); 
		echo"<script>history.go(-1);</script>";
	  	//ShowMsg("消息发送成功！","-1",0,2000);
	  }
}
else
{
	echo"<script>history.go(-1);</script>";
	//ShowMsg("本页面禁止返回!","javascript:window.close();");
}